export default {
  data() {
    return {
      shopid: '', //店铺id
      carid: '', //车id
      sAmount: '', //人数
      colorlist: [], //颜色
      shoplist: {}, //店铺list
      modify: '修改',
      modifycolor: '不限',
      colorpopup: false, //颜色弹框
      mobiles: '', //手机号
      phonemobiles: '', //手机号
      multiArray: [
        [],
        ['10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00',
          '17:00', '18:00'
        ],
      ], //日期时间集合
      multiIndex: [0, 0], //弹框显示两组数据
      datelist: [], //所有日期list
      xzdatatime: '', //传给后台日期
      htdatatime: '', //传给后台日期时分秒
      ymdatatime: '', //页面显示日期
      showdatatime: false, //时间弹框
      wgColorList: [], //外观颜色list
      nsColorList: [], //内试颜色list
      xedColorList: {
        outerColour: {
          colorCoding: '',
          color: ''
        },
        inColour: {
          colorCoding: '',
          color: '',
          neiColor: [{}]
        }
      }, //选择的颜色集合
      showPopup: false,
      colorlists: [],
      Storeid: '',
      carname: '',
      lon: '0',
      lat: '0',
      today: '',
    }
  },

  onLoad(shopid) {
    this.carid = shopid.carid
    this.carname = shopid.namecar
    this.sAmount = shopid.sAmount
    var colorlists
    colorlists = JSON.parse(shopid.colorList)
    colorlists.forEach(item => {
      this.wgColorList.push(item.outerColour) //外观颜色
      this.nsColorList.push(item.inColour) //内试颜色
    })
    this.wgColorList.forEach(item => {
      item.chekd = false
    })
    this.nsColorList.forEach(item => {
      item.chekd = false
    })
    if (shopid.typdei === '110') {
      this.shopid = shopid.stopid
      this.GetStoreInfo()
    }
    uni.$on('Storeid', data => {
      Object.assign(this.Storeid, data)
      this.shopid = data.Storeid
      this.GetStoreInfo()
    })

    this.lon = JSON.stringify(this.$store.state.lon)
    this.lat = JSON.stringify(this.$store.state.lat)

    //缓存中取到姓名和手机号
    const value = uni.getStorageSync('Ztc_C_USER_INFO')
    if (value) {
      this.mobiles = value.mobile
    }
  },
  created: function() {
    var arr = []
    var dats = []
    var dates = new Date
    var year = dates.getFullYear()
    var mouth = dates.getMonth() + 1
    var day = dates.getDate()
    var daynumber = Number(day)
    var danum = daynumber + 1
    var strds = '（周' + '日一二三四五六'.charAt(new Date().getDay()) + '）'
    // console.log(strds)
    if (mouth < 10) {
      mouth = '0' + mouth
    }
    if (day < 10) {
      day = '0' + day
    }
    if (danum < 10) {
      danum = '0' + danum
    }
    var jiaday = danum
    var str = year + '-' + mouth + '-' + day + strds
    this.today = year + '-' + mouth + '-' + jiaday + strds + '10:00'
    this.ymdatatime = year + '-' + mouth + '-' + jiaday + strds + '10:00' //页面显示
    this.xzdatatime = year + '-' + mouth + '-' + jiaday //传后台
    this.htdatatime = '10:00' //传后台
    var index = 0
    var strm
    var strd
    for (var i = 1; i <= 12; i++) {
      arr.push(this.mGetDate(year, i))
    }
    // arr为每个月多少天
    for (var j = 0; j < arr.length; j++) {
      for (var x = 0; x < arr[j]; x++) {
        strm = parseInt(j + 1)
        if (parseInt(j) < 9) {
          strm = '0' + parseInt(j + 1)
        }
        strd = parseInt(x + 1)
        if (parseInt(x) < 9) {
          strd = '0' + parseInt(x + 1)
        }
        dats.push(year + '-' + strm + '-' + strd)
        this.datelist = dats
      }
    }
    // index 为当前日期所对应的下标。
    var zm = []
    for (var z = 0; z < dats.length; z++) {
      var strdz = '（周' + '日一二三四五六'.charAt(new Date(dats[z]).getDay())+'）'
      zm.push(dats[z] + strdz)
    }
    // console.log(zm, '02313123')
    // this.multiArray[0] = dats // dats 为没有星期几的日期
    this.multiArray[0] = zm // dats 为没有星期几的日期
    for (var i = 0; i < zm.length; i++) {
      if (str === zm[i]) {
        index = i
      }
    }
    this.multiIndex[0] = index
  },
  methods: {
    //获取预约店铺信息
    async GetStoreInfo(type) {
      try {
        const res = await this.$api.commodity.GetStoreInfo({
          storeId: this.shopid || "",
          lat: this.lat,
          lon: this.lon
        })
        this.shoplist = res.data
        this.phonemobiles = res.data.phone
      } catch (err) {}
    },
    // 点击导航
    onClickNavigation() {
      uni.openLocation({
        latitude: this.shoplist.lat,
        longitude: this.shoplist.lon
      })
    },
    //手机号修改
    wancheclick() {
      this.modify = this.modify === '修改' ? '完成' : '修改'
    },
    //清空
    clearIcon() {
      this.mobiles = ''
    },
    mGetDate: function(year, month) {
      var d = new Date(year, month, 0)
      return d.getDate()
    },
    yuyebtnclickan() {
      // this.showdatatime = true
    },
    yuyebtnclick(ys) {
      var zm = []
      for (var z = 0; z < this.datelist.length; z++) {
        var strdz = '（周' + '日一二三四五六'.charAt(new Date(this.datelist[z]).getDay())+'）'
        zm.push(this.datelist[z] + strdz)
      }
      var datatimejt = this.today.split('-')[0] + this.today.split('-')[1] + this.today.split('-')[2]
      // console.log('今天', datatimejt)
      var xudata
      //页面显示
      zm.forEach((item, i) => {
        if (i === ys.detail.value[0]) {
          xudata = item.split('-')[0] + item.split('-')[1] + item.split('-')[2]
          // console.log('选择xudata', xudata)
          if (xudata < datatimejt) {
            this.$refs.uToast.show({
              title: '请选择今天之后的日期',
              icon: false,
              type: 'warning',
            })
            this.ymdatatime = this.today
            // console.log('选择ymdatatime', this.ymdatatime)
            return false
          } else {
            this.ymdatatime = item
          }
        }
      })
      if (xudata < datatimejt) {
        return false
      } else {
        //页面显示时分秒
        this.multiArray[1].forEach((item, i) => {
          if (i === ys.detail.value[1]) {
            this.ymdatatime = this.ymdatatime + item
            this.htdatatime = item
          }
        })
        //传给后台
        this.datelist.forEach((item, i) => {
          if (i === ys.detail.value[0]) {
            this.xzdatatime = item
          }
        })
        this.multiIndex[0] = ys.detail.value[0]
        this.multiIndex[1] = ys.detail.value[1]
      }

    },
    quxiaobtn() {
      console.log(23)
      this.showdatatime = true
    },
    dakaibtn() {
      console.log(23)
      this.showdatatime = false
    },
    // 颜色弹框
    colorClick() {
      this.colorpopup = true
    },
    //外观颜色
    wgcolorClick(item, index) {
      let listbox = [] //暂存赋值
      this.wgColorList.forEach((item, i) => {
        if (i === index) {
          if (item.chekd === false) {
            item.chekd = true
          } else {}
        } else {
          item.chekd = false
        }
        listbox.push(item)
      })
      this.wgColorList = listbox
      this.xedColorList.outerColour = item
      this.modifycolor = ''
    },
    //内饰颜色
    nsColorClick(item, index) {
      let listbox = [] //暂存赋值
      this.nsColorList.forEach((item, i) => {
        if (i === index) {
          if (item.chekd === false) {
            item.chekd = true
          } else {}
        } else {
          item.chekd = false
        }
        listbox.push(item)
      })
      this.nsColorList = listbox
      this.xedColorList.inColour = item
      this.modifycolor = ''
    },
    //确认预约
    qurclickbtn() {
      this.AddNewCarBook()
    },
    async AddNewCarBook(type) {
      var datatimes = this.xzdatatime + ' ' + this.htdatatime
      try {
        const res = await this.$api.commodity.AddNewCarBook({
          carId: this.carid,
          mobile: this.mobiles,
          bookTime: datatimes,
          storeId: this.shopid,
          color: this.xedColorList
        })
        if (res.code === 200) {
          this.showPopup = true
        }
      } catch (err) {}
    },
    //跳转列表
    agreepopup() {
      uni.navigateTo({
        url: '/pages_order/buy_order/buy_order?type=1&index=2'
      })
    },
    //关闭弹窗
    guanbianniu() {
      this.showPopup = false
    },
    gehClick() {
      uni.navigateTo({
        url: '/pages_commodity/storeSelection/storeSelection?carid=' + this.carid
      })
    },
    mobile() {
      uni.makePhoneCall({
        phoneNumber: this.phonemobiles //仅为示例
      })
    }
  }
}
